// pages/basics/home/index.js
var util = require('../../../utils/util.js')
var wxRequest = require('../../../utils/wxRequest.js')
var app = getApp();
// pages/component/list.js
Component({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    picList:[],
    stopLoadMoreTiem:false
  },
  //组件的生命周期
  lifetimes: {
    created: function () {
      // 在组件实例刚刚被创建时执行
      var that = this;  
    },
    attached: function() {
      // 在组件实例进入页面节点树时执行
      console.log("11111")
      this.getPackages();
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  methods:{
    showTip:function(){
      wx.showToast({
        title: 'title',
      })
    },
    golist:function(e){
      var id = e.currentTarget.id,
      url = '/pages/component/list/list?id=' + id;
      wx.navigateTo({
        url: url
      })
    },
    //上拉
    lower:function(){
      var that = this;
      that.setData({isPull:false});
      console.log("lower");
      if (that.stopLoadMoreTiem) {
        return;
      }
      this.setData({
        page: this.data.page + 1 //上拉到底时将page+1后再调取列表接口
      });
      this.getPackages();
    },
    getPackages:function(){
      var that = this;
      var data = {
        page : that.data.page
      }
      var res = util.getPackages(data);
      res.then(function(json){
        
            that.setData({
              picList:that.data.picList.concat(JSON.parse(json.data.result)),
            });
            that.stopLoadMoreTiem = false;
      });
    }
  }
})